package com.health.institution.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.institution.domain.Department;
import com.health.institution.service.IDepartmentService;

/**
 * 科室管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/institution/department")
public class DepartmentController extends BaseController
{
    @Autowired
    private IDepartmentService departmentService;

    /**
     * 查询所有一级科室
     */
    @GetMapping("/primary")
    public AjaxResult listPrimaryDepartments()
    {
        List<Department> list = departmentService.selectPrimaryDepartments();
        return success(list);
    }
    
    /**
     * 根据父科室ID查询子科室
     */
    @GetMapping("/children/{parentId}")
    public AjaxResult listChildrenDepartments(@PathVariable("parentId") Long parentId)
    {
        List<Department> list = departmentService.selectDepartmentsByParentId(parentId);
        return success(list);
    }
    
    /**
     * 查询所有科室
     */
    @GetMapping("/tree")
    public AjaxResult listDepartmentTree()
    {
        List<Department> list = departmentService.selectDepartmentTree();
        return success(list);
    }
}